<?php
function user_ip(){
    if (isset($_SERVER)){
        if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
            $userIP = $_SERVER["HTTP_X_FORWARDED_FOR"];
        } else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
            $userIP = $_SERVER["HTTP_CLIENT_IP"];
        } else {
            $userIP = $_SERVER["REMOTE_ADDR"];
        }
    } else {
        if (getenv("HTTP_X_FORWARDED_FOR")){
            $userIP = getenv("HTTP_X_FORWARDED_FOR");
        } else if (getenv("HTTP_CLIENT_IP")) {
            $userIP = getenv("HTTP_CLIENT_IP");
        } else {
            $userIP = getenv("REMOTE_ADDR");
        }
    }

    return $userIP;
}
function array_two_one($data , $key){
    $re=array();
    foreach ($data as $k => $val){
        $re[]=$val[$key];
    }
    return $re;
}
function getCatId($catId){
    $cat=M('Category');
    $catli=$cat->where('id='.$catId)->find();
    if($catli['level'] == 2){
        $cat_ID= $catli['id'];
    }else{
        getCatId($catli['parent_id']);
    }
    return $cat_ID;
}